//Fusion of the 422 Proportion
//Dustin Striplin, Tyler Simrell, Lawrence Grass, and Jacob Hall
//Finished 5/1/13

package view;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import model.PageInfo;

/**
 * The CurrentResultsPanel class for the webcrawler program
 * @author Lawrence Grass
 * @version 4/28/13
 */
@SuppressWarnings("serial")
public class CurrentResultsPanel extends JPanel{
	
	private JTextArea display = new JTextArea();
	
	private int numberOfPagesParsed = 0;
	
	public CurrentResultsPanel(){
		this.setLayout(new BorderLayout());
		JPanel titlePanel = new JPanel();
		titlePanel.setPreferredSize(new Dimension(380, 40));
		JLabel title = new JLabel("Running Results");
		titlePanel.add(title);
		this.add(titlePanel, BorderLayout.NORTH);
		display.setEditable(false);
		JScrollPane mainPane = new JScrollPane(display);
		mainPane.setPreferredSize(new Dimension(380, 600));
		this.add(mainPane, BorderLayout.CENTER);
	}
	
	public void insertResult(PageInfo page){
		numberOfPagesParsed++;
		display.append("\n"
					  + "Parsed: " + page.getURL() + "\n"
					  + "Pages Retrieved: " + numberOfPagesParsed + "\n"
					  + "Average words per page: " + page.getAveWordsPerPage() + "\n"
					  + "Average URLs per page: " + page.getAveURLsPerPage() + "\n"
					  + "Keyword      Avg. hits per page      Total hits\n");
		for(String key: page.getKeyWordMap().keySet()){
			display.append("    " + key + "\t" + String.format("%10.6f", page.getKeywordAveHitsMap().get(key)) + 
					"\t       " + page.getKeywordTotalHitsMap().get(key) + "\n");
		}
		display.append("Page limit: " + page.getPageLimit() + "\n"
					  + "Average parse time per page: " + page.getAveParseTimePerPage() + "\n"
					  + "Total running time: " + page.getTotalRunTime() + "\n"
					  + "---------------------------------------------------------\n");
		display.revalidate();
		display.setCaretPosition(display.getDocument().getLength());
	}
}
